package com;


import com.threegene.microlecture.common.utils.HttpRequestUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class TaobaoIpQry {

    public static void main(String[] args) throws IOException, InterruptedException {

        for(int i = 0; i < 100; i++){
            qry();
            /*
            new Thread(){
                @Override
                public void run() {
                    try {
                        qry();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
            Thread.sleep(1000);
            */
        }
    }

    public static void qry() throws IOException {
        String ip = "121.35.211.41";
        String url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip;
//        String url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=" + ip;

        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER");
        headerMap.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        headerMap.put("Accept-Encoding", "gzip, deflate, sdch");
        headerMap.put("Accept-Language", "zh-CN,zh;q=0.8");
        headerMap.put("Cache-Control", "max-age=0");
        headerMap.put("Connection", "keep-alive");
        headerMap.put("Upgrade-Insecure-Requests", "1");
        headerMap.put("Cookie", "thw=cn");

        long start = System.currentTimeMillis();
        String s = HttpRequestUtil.httpPostJson(url, "", headerMap);
        System.out.print(s);
        System.out.println(System.currentTimeMillis()-start + "ms");
        //{"code":0,"data":{"ip":"121.35.211.41","country":"中国","area":"","region":"广东","city":"深圳","county":"XX","isp":"电信","country_id":"CN","area_id":"","region_id":"440000","city_id":"440300","county_id":"xx","isp_id":"100017"}}
    }


}
